package hk.m4s.lr.repair.test.ui.adapter;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.MaintenancekModel;
import hk.m4s.lr.repair.test.model.projectModle;
import hk.m4s.lr.repair.test.ui.baoyang.SqcanDeviceBaoActivity;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 
 * @author
 * 
 */
public class RepairPartslAdapter extends BaseAdapter {
	private Context context;
	public List<MaintenancekModel.ProjectBean> items;

	// /** volley 图像加载器 */
	// private ImageLoader imageLoader;

	public RepairPartslAdapter(Context context, List<MaintenancekModel.ProjectBean> items) {
		this.context = context;
		this.items = items;
		// imageLoader = RequestManager.getImageLoader();
	}

	public int getCount() {
		return items.size();
	}

	public Object getItem(int position) {
		return getView(position, null, null);
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.grid_item_repair_parts, null);
		}
		if (position >= items.size()) {
			return convertView;
		}
		final MaintenancekModel.ProjectBean item = items.get(position);
		// 设置维修项目名称
		TextView tvItem = (TextView) convertView;
		tvItem.setText(item.getName());
		tvItem.setTag(position);
		// 设置是否选中
		if (item.getState().equals("1")) {
			tvItem.setBackgroundResource(R.drawable.checked_backroud);
			tvItem.setTextColor(Color.parseColor("#ffffff"));
		} else {
			tvItem.setBackgroundResource(R.drawable.check_backroud);
			tvItem.setTextColor(Color.parseColor("#000000"));
		}
		tvItem.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				int num=(Integer)v.getTag();
				MaintenancekModel.ProjectBean item = items.get(num);
				if(item.getState().equals("1")){
					item.setState("-1");
				}else{
					item.setState("1");
				}
				items.set(num,item);
				notifyDataSetChanged();
			}
		});
		return convertView;
	}
}
